<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="10" :lg="11" :md="12" :sm="24">
            <a-form-item :label="$t('核销时间')">
              <j-date
                :show-time="{ defaultValue: moment('00:00:00', 'HH:mm:ss') }"
                valueFormat="YYYY-MM-DD HH:mm:ss"
                dateFormat="YYYY-MM-DD HH:mm:ss"
                :placeholder="$t('请选择开始时间')"
                class="query-group-cust"
                v-model="queryParam.createTime_begin"
              ></j-date>
              <span class="query-group-split-cust"></span>
              <j-date
                :show-time="{ defaultValue: moment('23:59:59', 'HH:mm:ss') }"
                valueFormat="YYYY-MM-DD HH:mm:ss"
                dateFormat="YYYY-MM-DD HH:mm:ss"
                :placeholder="$t('请选择结束时间')"
                class="query-group-cust"
                v-model="queryParam.createTime_end"
              ></j-date>
            </a-form-item>
          </a-col>
          <a-col :xl="5" :lg="6" :md="7" :sm="24">
            <a-form-item :label="$t('核销订单号')">
              <a-input :placeholder="$t('请输入核销订单号')" v-model="queryParam.orderId"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xl="8" :lg="9" :md="10" :sm="24">
            <span style="float: left; overflow: hidden" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">{{$t('查询')}}</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">{{$t('重置')}}</a-button>
              <a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? $t('收起') : $t('展开') }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'" />
              </a>
              <a-button
                type="primary"
                icon="download" :loading="exloading"
                style="margin-left: 8px"
                @click="handleExportXls($t('美团套餐核销记录报表'))"
                v-has="'BisMeituanGoodsUseController:export'"
                >{{$t('导出')}}</a-button
              >
            </span>
          </a-col>
        </a-row>
        <a-row :gutter="24">
          <template v-if="toggleSearchStatus">
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item :label="$t('美团订单号')">
                <a-input :placeholder="$t('请输入美团订单号')" v-model="queryParam.buyOrderId"></a-input>
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item :label="$t('美团套餐ID')">
                <a-input :placeholder="$t('请输入美团套餐ID')" v-model="queryParam.meituanGoodsId"></a-input>
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item :label="$t('点评团购ID')">
                <a-input :placeholder="$t('请输入点评团购ID')" v-model="queryParam.dealId"></a-input>
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item :label="$t('商品名称')">
                <a-input :placeholder="$t('请输入商品名称')" v-model="queryParam.name"></a-input>
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item :label="$t('验证券码')">
                <a-input :placeholder="$t('请输入验证券码')" v-model="queryParam.receiptCode"></a-input>
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item :label="$t('操作员')">
                <a-select v-model="queryParam.createBy">
                  <a-select-option v-for="(item, index) in userList" :key="index" :value="item.value">
                    {{ item.title }}
                  </a-select-option>
                </a-select>
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item :label="$t('设备名称')">
                <a-select v-model="queryParam.deviceId">
                  <a-select-option v-for="(item, index) in deviceList" :key="index" :value="item.value">
                    {{ item.title }}
                  </a-select-option>
                </a-select>
              </a-form-item>
            </a-col>
          </template>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->

    <!-- table区域-begin -->
    <div>
      <a-table
        ref="table"
        size="middle"
        :scroll="{ x: true }"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        class="j-table-force-nowrap"
        @change="handleTableChange"
      >
        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px; font-style: italic">{{$t('无图片')}}</span>
          <img
            v-else
            :src="getImgView(text)"
            height="25px"
            alt=""
            style="max-width: 80px; font-size: 12px; font-style: italic"
          />
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px; font-style: italic">{{$t('无文件')}}</span>
          <a-button v-else :ghost="true" type="primary" icon="download" size="small" @click="downloadFile(text)">
            {{$t('下载')}}
          </a-button>
        </template>
        <template slot="footer">
          <div style="font-weight: bold">
            <span style="margin-left: 15px;margin-right: 5px">{{$t('销售金额')}}：</span>
            <span>{{ (totalInfo.salePrice||totalInfo.salePrice===0||totalInfo.salePrice==='0')?totalInfo.salePrice.toFixed(2):"0.00" }}</span>
            <span v-if="meituanAppType==0" style="margin-left: 15px;margin-right: 5px">{{$t('支付金额')}}：</span>
            <span v-if="meituanAppType==0">{{ (totalInfo.payAmount||totalInfo.payAmount===0||totalInfo.payAmount==='0')?totalInfo.payAmount.toFixed(2):"0.00" }}</span>
          </div>
        </template>
      </a-table>
    </div>
  </a-card>
</template>

<script>
import moment from 'moment'
import '@/assets/less/TableExpand.less'
import { mixinDevice } from '@/utils/mixin'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import { initDictOptions } from '@/components/dict/JDictSelectUtil'

export default {
  name: 'MTPackageVerificationRecord',
  mixins: [JeecgListMixin,mixinDevice],
  components: {},
  data() {
    return {
      moment,
      description: '美团套餐核销记录管理页面',
      queryParam: {
        deviceId: '',
        createBy: '',
      },
      // 表头
      columns: [
        {
          title: this.$t('核销时间'),
          align: 'center',
          dataIndex: 'createTime',
        },
        {
          title: this.$t('核销订单号'),
          align: 'center',
          dataIndex: 'orderId',
        },
        {
          title: this.$t('美团订单号'),
          align: 'center',
          dataIndex: 'buyOrderId',
        },
        {
          title: this.$t('美团套餐ID'),
          align: 'center',
          dataIndex: 'meituanGoodsId',
        },
        {
          title: this.$t('点评团购ID'),
          align: 'center',
          dataIndex: 'dealId',
        },
        {
          title: this.$t('商品名称'),
          align: 'center',
          dataIndex: 'name',
        },
        {
          title: this.$t('手机号'),
          align: 'center',
          dataIndex: 'phone',
        },
        {
          title: this.$t('销售金额'),
          align: 'center',
          dataIndex: 'salePrice',
          customCell: () => {
            return {
              style: {
                textAlign: 'right',
              },
            }
          },
          customRender: (text, record) => {
            return record.salePrice.toFixed(2)
          },
        },
        {
          title: this.$t('验证券码'),
          align: 'center',
          dataIndex: 'receiptCode',
        },
        {
          title: this.$t('核销数量'),
          align: 'center',
          dataIndex: 'count',
          customCell: () => {
            return {
              style: {
                textAlign: 'right',
              },
            }
          },
          customRender: (text, r) => {
            text = (text ==null || text =="" || text ==undefined)?0:parseFloat(text);
            return text.toFixed(0);
          }
        },
        {
          title: this.$t('操作员'),
          align: 'center',
          dataIndex: 'createBy',
        },
        {
          title: this.$t('设备名称'),
          align: 'center',
          dataIndex: 'deviceId_dictText',
        },
        {
          title: this.$t('设备编码'),
          align: 'center',
          dataIndex: 'deviceId',
        },
      ],
      url: {
        list: '/meituan/bisMeituanGoodsUse/list',
        exportXlsUrl: '/meituan/bisMeituanGoodsUse/exportXls',
        totalUrl: "/meituan/bisMeituanGoodsUse/total"
      },
      dictOptions: {},
      superFieldList: [],
      deviceList: [],
      userList: [],
      isfooter:true,
      totalInfo:{
        salePrice:0,
        payAmount:0
      },
      meituanAppType: localStorage.getItem('meituanAppType')
    }
  },
  created() {
    if (this.meituanAppType == 0) {
      this.columns.splice(8, 0,{
        title: this.$t('支付金额'),
        align: 'center',
        dataIndex: 'payAmount',
        customCell: () => {
          return {
            style: {
              textAlign: 'right',
            },
          }
        },
        customRender: (text, record) => {
          return record.payAmount.toFixed(2)
        },
      })
    }
  },
  computed: {
    importExcelUrl: function () {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
    },
  },
  methods: {
    initDictConfig() {
      initDictOptions('bis_device_info,name,id').then((res) => {
        if (res.success) {
          this.deviceList = res.result
          this.deviceList.unshift({ title: this.$t('全部'), value: '' })
        }
      }),
      initDictOptions('sys_user,realname,realname').then((res) => {
        if (res.success) {
          this.userList = res.result
          this.userList.unshift({ title: this.$t('全部'), value: '' })
        }
      })
    },
    searchReset() {
      this.queryParam = {
        deviceId: '',
        createBy: '',
      }
      this.searchQuery()
    },
  },
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>